var prefs = Components.classes["@mozilla.org/preferences-service;1"].
                getService(Components.interfaces.nsIPrefBranch);

function init() {

	var streamSize = 20;
	var thumbSize = 't';
	var singlephoto = 0;

	try {
		streamSize = prefs.getIntPref("cn.xpies.yupoofox.streamsize");
	} catch(e) { //pass
	}
	var ss = document.getElementById('prefsize').setAttribute('value',streamSize);

	try {
		thumbSize = prefs.getCharPref("cn.xpies.yupoofox.thumbsize");
	} catch(e) { //pass
	}

	try {
		singlephoto = prefs.getIntPref("cn.xpies.yupoofox.singlephoto");
	} catch(e) { //pass
	}

	tsID = "ff_t_" + thumbSize;
	document.getElementById(tsID).setAttribute('selected',true);
	if (singlephoto == 1) {
		document.getElementById('singlephoto').checked = true;
	}
}

function savePrefs() {
	var s = document.getElementById('prefsize');
	var t = document.getElementById('prefthumbsize');
	var single = document.getElementById('singlephoto');
	var thumbSize;

	s = parseInt(s.value);
	if (isNaN(s)==false) {
	  if (s > 100) {
	      s = 100;
	  }
	  if (s < 1) {
	      s = 20;
	  }
	} else {
	  s = 20;
	}

	var singlephoto = 0;
	if (single.checked == true) {
	      singlephoto = 1;
	}

	if (t.value == '') {

	      try {
		  thumbSize = prefs.getCharPref("cn.xpies.yupoofox.thumbsize");
	      } catch(e) {
		  thumbSize = 't';
	      }
	  t.value = thumbSize;
	}

	prefs.setIntPref("cn.xpies.yupoofox.streamsize", s);
	prefs.setCharPref("cn.xpies.yupoofox.thumbsize", t.value);
	prefs.setIntPref("cn.xpies.yupoofox.singlephoto", singlephoto);

	var par = window.opener.document.getElementById("tools-yupoofox-refresh");
	try {
	 par.click();
	} catch(e) {
	//pass
	}
	window.close();
}

